<?php

class Ext_Auth_Adapter
{
    private static $_adapter = null;

    public function __construct($username, $password)
    {
    	if(self::$_adapter === null)
    	{
    		$front = Zend_Controller_Front::getInstance();
			$bootstrap = $front->getParam('bootstrap');
			$options = $bootstrap->getApplication()->getOptions();
			
	    	$classname = "Ext_Auth_Adapter_".ucfirst($options['auth']['adapter']['self']);
	    	if(!class_exists( $classname ))
	    	{
	    		require_once 'Zend/Auth/Exception.php';
	          	throw new Zend_Auth_Exception("Auth adapter '".self::$_adapter."' is not exists.");
	    	}

	    	self::$_adapter = new $classname($username, $password);
    	}
    }
    
    public function getAdapter()
    {
    	return self::$_adapter;
    }
    
    public function authenticate()
    {
		$_result = self::$_adapter->authenticate();
		
		return $_result;
    }
}
